package com.anuo.app.common.utils;


import org.quartz.Scheduler;
import org.quartz.impl.StdScheduler;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 * 任务调度工具类
 */
public class QuartzUtil {
    private static ApplicationContext applicationContext;
    private static QuartzUtil instance;

    public QuartzUtil getInstance() {
        if (instance == null) {
            instance = new QuartzUtil();
        }
        return instance;
    }

    public static ApplicationContext getApplicationContext() {
        if (applicationContext == null) {
            applicationContext = new ClassPathXmlApplicationContext("spring/spring-quartz.xml");
        }
        return applicationContext;
    }

    public static Scheduler getScheduler() {
        return (StdScheduler) getApplicationContext().getBean("quartzScheduler");//name 值为 quartz.properties 中 instanceName 值
    }

}

